# include<stdio.h>
# include <stdlib.h>
# include <conio.h>
# include <windows.h>
# include "mastructure.h"
# include "general.h"

struct grille T_solution[8][8];


int jouer_expert(struct grille tabGrille[8][8])
{
int i,x,y,z,v,continuer;
system("cls");
color_console(0,0);
afficher(tabGrille,8);
printf("tapez une ligne\n");
scanf("%d",&x);
x=x-1;
while(x==0)
{
printf("vous ne pouvez pas taper la ligne 1 veuillez taper une autre ligne\n");
scanf("%d",&x);
x=x-1;
}
printf("tapez une colonne\n");
scanf("%d",&y);
y=y-1;
while(y==0)
{
printf("vous ne pouvez pas taper la colonne 1 veuillez taper une autre colonne\n");
scanf("%d",&y);
y=y-1;
}
printf("tapez une valeur entre 1 ET 9\n");
scanf("%d",&z);
if ((z>=1)&&(z<=9))
{
tabGrille[x][y].val0=z;
}
afficher(tabGrille,8);

printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("voulez vous continuer? tapez 1 sinon tapez un autre chiffre \n");
scanf("%d",&continuer);
v=verification(tabGrille,8);
if ((v==1)&&(continuer==1))
{

jouer_expert(tabGrille);

}

return 0;
}

void afficher_solution_E(struct grille tab[8][8],int niveau,int test)
{
    int i,j,k=0,espacement_x,espacement_y;
    if (niveau==4)
    {
      espacement_x=22;
      espacement_y=9;
      }
    if (niveau==6)
    {
      espacement_x=5;
      espacement_y=4;
    }

      if(niveau==8)
    {
      espacement_x=5;
      espacement_y=6;
      }
    for(i=0;i<niveau;i++)
    {

        move_cursor(espacement_x,3+k+espacement_y);
        for (j=0;j<niveau;j++)
        {
             color_console(0,15);
             printf(" ------ ");
             printf(" ");
        }
        printf("\n");
        k++;
        move_cursor(espacement_x,3+k+espacement_y);
        for(j=0;j<niveau;j++)
        {
           if (tab[i][j].attrib==0)
                {
                    if (tab[i][j].attrib2==0)
                        {
                        printf("|  -   | ");
                        }
                        if (tab[i][j].attrib2==1)
                        {
                            if((tab[i][j].val1/10>=1)&&(tab[i][j].val2/10<1))
                            {
                            printf("|%d / %d| ",tab[i][j].val1,tab[i][j].val2);
                            }
                            if((tab[i][j].val1/10<1)&&(tab[i][j].val2/10>=1))
                            {
                            printf("|  %d/%d| ",tab[i][j].val1,tab[i][j].val2);
                            }
                            if ((tab[i][j].val1/10>=1)&&(tab[i][j].val2/10>=1))
                            {
                        printf("| %d/%d| ",tab[i][j].val1,tab[i][j].val2);
                            }
                                }
                    }

                if (tab[i][j].attrib==1)
                {
                    if (tab[i][j].attrib2==0) { if(tab[i][j].val1/10>=1)
                                    {
                                        printf("|  %d  | ",tab[i][j].val1);
                                    }
                                    else
                                    {
                                        printf("|  %d   | ",tab[i][j].val1);
                                    }
                                }
                        if ((tab[i][j].attrib2==1)&&(tab[i][j].val0==0)&&(test==0))
                        {
                            printf("|      | ");

                        }
                        if ((tab[i][j].attrib2==1)&&(tab[i][j].val0!=0)&&(test==0))
                        {
                            printf("|  %d   | ",tab[i][j].val0);
                        }
                         if ((tab[i][j].attrib2==1)&&(tab[i][j].val0!=0)&&(test==1))
                         {
                            printf("|  %d   | ",tab[i][j].val0);
                         }
                    }

        }
        k++;
        printf("\n");
        move_cursor(espacement_x,3+k+espacement_y);
        for (j=0;j<niveau;j++)
        {
                printf("|______| ");

        }
        printf("\n");
        k++;
        move_cursor(espacement_x,3+k+espacement_y);}
        printf("\n");
    }


void noyau_expert()
{
int test_jouer=0;
charger_grille("./grilles/expert/grille1.txt",tabGrille,8);
afficher(tabGrille,8);
jouer_expert(tabGrille);
charger_grille("./grilles/expert/grille1c.txt",T_solution,8);
corriger(tabGrille,T_solution,8);
getch();
afficher_solution_F(T_solution,8,1);
}
